<?php

namespace App\Console\Commands;

use App\Models\Nations;
use App\Models\PoliticalOutlook;
use App\Models\SchoolStatus;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class InitSelectList extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'init:select';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        DB::table('nations')->truncate();
        DB::table('political_outlook')->truncate();
        DB::table('school_statuses')->truncate();
        $result = \College::getNations();
        foreach ($result as $item){
          $nat =  new Nations();
          $nat->key = $item->mzdm;
          $nat->value = $item->mzmc;
          $nat->save();
        }
        $result = \College::getMianMao();

        foreach ($result as $item){
            $pol = new PoliticalOutlook();
            $pol->value = $item->zzmmmc;
            $pol->key = $item->zzmmdm;
            $pol->save();
        }
        $result = \College::geXueji();
        foreach ($result as $item){
            $pol = new SchoolStatus();
            $pol->value = $item->xsm;
            $pol->key = $item->xsh;
            $pol->save();
        }
    }
}
